<template>
    <div class="components_edit_modal">
        <el-dialog title="修改调查问卷" :visible.sync="state" :show-close="true" :close-on-click-modal="false">
            <el-form :model="questionnaireParams"   :rules="rules" ref="questionnaireParams" label-position="right" :close-on-click-modal="false">

                        <el-form-item label="名称"  prop="questionnaireName" class="lineblock">
                                <el-input v-model.trim="questionnaireParams.questionnaireName" placeholder="请输入名称"></el-input>
                        </el-form-item>
                        
                        <el-form-item label="备注" prop="remark" class="lineblock textareaBox">
                                <el-input v-model.trim="questionnaireParams.remark" type="textarea"  placeholder="请输入备注"></el-input>
                        </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" size="small" @click="editQuestionnaire('questionnaireParams')">确 定</el-button>
                <el-button size="small" @click="state = false">关 闭</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {enums} from '@/constant'
    export default {
        components: {

        },
        data() {
            return {
                 state: false,
                 rules: {
                    questionnaireName: [
                        { required: true, message: '调查问卷名称不能为空', trigger: 'blur',type:"string"},
                    ],
                 },
                questionnaireParams: {
                    questionnaireName:null,
                    remark:null
                }
            }
        },
        created() {
            
        },
        mounted() {},
        methods: {
            // 编辑专业
            editQuestionnaire(questionnaireName) {
                let self = this;
                this.$refs['questionnaireParams'].validate((valid) => {
                    if (valid) {
                        let url = api.questionnaire.edit;
                        this.axios.put(url,self.questionnaireParams)
                        .then((response) => {
                            if (response.data.success) {
                                self.$message({
                                    type: 'success',
                                    message: response.data.msg,
                                });
                                self.$parent.$refs.questionnaireTable.$emit('vuetable:refresh');
                                self.state = false;
                            } else {
                                self.$message.error(response.data.msg);
                            }
                            
                        })
                    } else {
                        return false;
                    }
                });
            },
            showDialog(id){
                let self = this;
                if(this.$refs['questionnaireParams']!==undefined){
                    this.$refs['questionnaireParams'].resetFields();
                }
                this.getQuestionnaireDetail(id,
                    (result)=>{
                        self.questionnaireParams.questionnaireName = result.questionnaireName;
                        self.questionnaireParams.remark = result.remark;
                        self.questionnaireParams.id = result.id;
                    });
                this.state = true;
            },
            getQuestionnaireDetail(id,success){
                let self = this;
                self.axios.get(api.questionnaire.detail + id).then((response) => {
                    if (response.data.success) {
                        success(response.data.data);
                    } else {
                        self.$message.error(response.data.msg);
                    }
                })
            }
        }
    };
</script>
<style scoped>

</style>